package com.wyh.day05.work;

/**
 * @author 王艺豪
 * @version 1.0
 */
public class work03 {
    public static void main(String[] args) {
        System.out.println(jie1(8));
        System.out.println(jie2(8));
    }

    // n 的阶乘
    //递归
    public static int jie1(int num) {
        if (num >= 1) {
            if (num == 1) return 1;
            return num * jie1(num - 1);
        } else {
            System.out.println("你输入的数字有误");
        }
        return -1;
    }

    //迭代
    public static int jie2(int num) {

        int res = 1;
        if (num >= 1) {
            if (num == 1) return 1;
            while (num > 0) {
                res *= num;
                num--;
            }
            return res;
        } else {
            System.out.println("你输入的数字有误");
        }
        return -1;
    }
}
